package com.lebang.common.util;

import com.lebang.common.validcode.Maths;
import com.lebang.entity.task.*;
import com.lebang.model.enums.buss.RewardMode;

import java.math.BigDecimal;

/**
 * @Author: hwq
 * @Date: 2019/5/29 13:56
 * @Version 1.0
 */

/**
 * 任务奖励计算工具类
 */
public class AmountUtil {





    public static int checkAmount(LbbCommon task) {
        int amount = 0;
        RewardMode mode = task.getReward();
        if (mode.equals(RewardMode.Fixed)) {
            amount = Integer.parseInt(task.getWorth());
        } else if (mode.equals(RewardMode.Random)) {
            String[] s = task.getWorth().split(":|：");
            amount = Maths.random(Integer.parseInt(s[0]), Integer.parseInt(s[1]));
        } else if (mode.equals(RewardMode.Rate)) {
            amount = new BigDecimal(task.getWorth()).divide(new BigDecimal(100))
                    .multiply(new BigDecimal(task.getIncrease())).intValue();
        }
        return amount;
    }
    public static int checkAmount(LbbSoso task) {
        int amount = 0;
        RewardMode mode = task.getReward();
        if (mode.equals(RewardMode.Fixed)) {
            amount = Integer.parseInt(task.getWorth());
        } else if (mode.equals(RewardMode.Random)) {
            String[] s = task.getWorth().split(":|：");
            amount = Maths.random(Integer.parseInt(s[0]), Integer.parseInt(s[1]));
        } else if (mode.equals(RewardMode.Rate)) {
            amount = new BigDecimal(task.getWorth()).divide(new BigDecimal(100))
                    .multiply(new BigDecimal(task.getIncrease())).intValue();
        }
        return amount;
    }

}
